home *** CD-ROM | disk | FTP | other *** search
/ PC Media 2 / PC MEDIA CD02.iso / share / prog / pb_menu / menulib.txt < prev    next >
Encoding:
Text File  |  1993-06-10  |  19.1 KB  |  573 lines

  1. Menulib for Menusys
  2. Add-On Library Routines
  3. for Power BASIC 3.0
  4. Version 1.0A
  5.  
  6. (C) Copyright 1993 by Tim Gerchmez
  7. ----------------------------------
  8.  
  9.  
  10.             ** SUB/Function Reference **
  11.  
  12.  
  13. Note: Especially powerful/high-level routines
  14.       are marked with "*P*" to distinguish
  15.       them from the rest.
  16.  
  17. Total Routines: 41
  18. ------------------------------------------------------------------------------
  19. * SUB about
  20.  
  21. Displays the title and author of the current program
  22. in a window and waits for the user to press ENTER or
  23. click "OK" with the mouse.  Source code version is
  24. required to modify this routine.
  25.  
  26. Example: CALL about
  27.  
  28. -----------------------------------------------------------------------------
  29. * SUB alertbox (msg$)
  30.  
  31. Prints a one-line alert message on the screen and
  32. waits for user to select OK with mouse or ENTER.
  33.  
  34. Example: CALL alertbox("File Not Found")
  35.  
  36. -----------------------------------------------------------------------------
  37. * SUB background (ch%)
  38.  
  39. Fills the screen with a special character, creating a
  40. background.  Uses colors in global variables clr% and bckg%.
  41. Set ch% = 0 for black background, 1 for dark background, 2 for medium,
  42. 3 for light, 4 for pure.
  43.  
  44. Example: CALL background(2)
  45.  
  46. -----------------------------------------------------------------------------
  47. * SUB bigprint (ch$, u$)
  48.  
  49. Prints a giant representation of the ASCII value in ch$.
  50. Uses the character in u$ to represent the "dots" for the big
  51. character.  Cursor Position is restored afterward.
  52.  
  53. Example: CALL bigprint ("A",chr$(219))
  54.  
  55. ------------------------------------------------------------------------------
  56. * SUB bigprintline (ln$, u$)
  57.  
  58. *P*
  59.  
  60. Print an entire line of characters in ln$ in giant size print.
  61. Uses the character in u$ to print the giant "pixels."
  62. Maximum: 10 characters in ln$ (80-col. screen).
  63. Ready to print another line after routine is called .. begins
  64. on the line the cursor is currently on.  Add 8 to the current
  65. Y position for the next "screen line".  One screen will hold
  66. about 3 lines of 10 giant characters.
  67.  
  68. Example:  LOCATE 1, 1
  69.       CALL bigprintline("Testing123",chr$(219))
  70.  
  71. -----------------------------------------------------------------------------
  72. * SUB checkbox (title$, optn$(), optn%())
  73.  
  74. Lets the user pick from a list of options with the mouse cursor or
  75. the keyboard.  More than one option can be selected.  Set title$
  76. to the title to display on the list, and DIM optn$() to the text
  77. for the list of options.  Upon return, optn%(x) will contain either
  78. a zero (user didn't select it) or a one (user selected it).  Subsequent
  79. calls to checkbox will retain the user's choices in optn% if the array
  80. isn't erased or redimensioned.
  81.  
  82. Example: title$="Select Options:":REDIM optn$(1:3), optn%(1:3)
  83.      optn$(1)="Option 1":optn$(2)="Option 2":optn$(3)="Option 3"
  84.      CALL checkbox(title$, optn$(), optn%())
  85.  
  86. -----------------------------------------------------------------------------
  87. * SUB choosebox (msg$(), choice%)
  88.  
  89. Prints a multi-line message on the screen in a box,
  90. and waits for user to select OK or CANCEL.
  91. Returns 0 (OK) or 1 (Cancel)
  92. Shortest string in msg$(x) should be >20.
  93. Returns with user's choice in choice%:
  94.  
  95. 0 = OK
  96. 1 = Cancel
  97.  
  98. Example: DIM msg$(1:2)
  99.      msg$(1)="Would you like to"
  100.      msg$(2)="Continue the current operation?"
  101.      CALL choosebox(msg$(), choice%)
  102.      IF choice% = 1 then print "Nope!" : end
  103.  
  104. -----------------------------------------------------------------------------
  105. * SUB choosedir (d$, ch$)
  106.  
  107. *P*
  108.  
  109. Lets a user select from a directory entry on the screen.  Includes
  110. ability to switch to new drives/subdirectories.  Call with d$ =
  111. directory mask (normally "*.*").  Routine returns with user's choice
  112. of filename in ch$ (or null string if cancelled).
  113.  
  114. Example: CALL choosedir("*.*",ch$)
  115.  
  116. -----------------------------------------------------------------------------
  117. * SUB clearline (ln%)
  118.  
  119. Clears a selected screenline, including position 80, without
  120. scrolling the screen.  Also preserves the current cursor position
  121. and turns off the mouse cursor if necessary.
  122.  
  123. Example: CALL clearline (25)
  124.  
  125. -----------------------------------------------------------------------------
  126. * FUNCTION endofline% (ln%)
  127.  
  128. Finds the position of the END OF TEXT on a specified screen line.
  129. For example, if line 20 of the screen had the line
  130.  
  131.  
  132. This is a test
  133.  
  134.           ^
  135.           15
  136.  
  137. on it, PRINT endofline%(20) would return 15 (the last character
  138. plus one, indicating the blank space following the line of text).
  139. If there is no text on the specified screen line, a value of 80
  140. will be returned.
  141.  
  142. Example: a% = endofline%(2)
  143.  
  144. -----------------------------------------------------------------------------
  145. * SUB getdisk (d%)
  146.  
  147. Returns drive code of current or default drive.
  148. 0 = A, 1 = B, 2 = C, Etc. in d%.
  149.  
  150. Example: CALL getdisk(d%)
  151.  
  152. -----------------------------------------------------------------------------
  153. * SUB getfontinfo (code%, points%, rows%, sg&, offset&)
  154.  
  155. EGA, MCGA, VGA
  156. Returns a pointer to a font's character definition table, and
  157. the points (bytes per character) and rows for that font.
  158. Call with code% set to one of the following values:
  159. 0 = INT 1fh contents, 1 = INT 43h contents, 2 = ROM 8x14
  160. font, 3 = ROM 8x8 font (chars 00h-7fh), 4 = ROM 8x8
  161. font (chars 80h-ffh), 5 = ROM alternate 9x14 font, 6 =
  162. ROM 8x16 font, 7 = ROM alternate 9x16 font.  Returns
  163. points%, rows%(char. rows on screen - 1), sg% (segment of
  164. char def table), offset% (offset of char. def table).
  165. Used internally by BIGPRINT and BIGPRINTLINE to define
  166. the shape of their giant character representations.
  167.  
  168. Example: CALL getfontinfo(3, points%, rows%, sg&, offset&)
  169.  
  170. -----------------------------------------------------------------------------
  171. * SUB getpath (dv%, pth$)
  172.  
  173. Gets the current path from the root directory to the
  174. current directory for the drive specified in dv%
  175. (0 = Default, 1 = A, Etc).
  176. Returns path in pth$ (including leading backslash).
  177. If error, pth$ will = "".
  178. Example: if current path was C:\PB\SLAM\, pth$
  179. would return \PB\SLAM\.  If path was C:\ then
  180. pth$ would return \.
  181.  
  182. Used internally by choosedir.
  183.  
  184. Example: CALL getpath(0, pth$)
  185.      print "Current Path: "; pth$
  186.  
  187. -----------------------------------------------------------------------------
  188. * SUB hscrollbar (starty%, startx%, length%)
  189.  
  190. Displays a horizontal "scroll bar" on the screen starting at position
  191. starty%/startx%m, of length% characters.  See the demo program for an
  192. example of hscrollbar.  This routine displays the scrollbar only - does
  193. not control scrolling or anything else.  You will have to write the
  194. routines yourself to display the scroll indicator, or wait for a future
  195. version of menulib <grin>.
  196.  
  197. Example: CALL hscrollbar (23, 1, 20)
  198.  
  199. -----------------------------------------------------------------------------
  200. * SUB infobox (msg$())
  201.  
  202. Prints a multi-line message on the screen in a box,
  203. and waits for user to select OK with mouse or ENTER.
  204. This differs from alertbox in that you can display
  205. more than one line of text in the box.
  206.  
  207. Example: DIM msg$(2)
  208.      msg$(1) = "Disk Problem -"
  209.      msg$(2) = "Select OK"
  210.      call infobox(msg$())
  211.  
  212. -----------------------------------------------------------------------------
  213. * SUB inpbox (msg$, ip$, mx%, ll%, ul%)
  214.  
  215. *P*
  216.  
  217. Allows user input in a shadowed screen box.
  218.  
  219. Set msg$ to message, mx% to max length of user input,
  220. ll% = lowest ASCII value permitted for input,
  221. ul% = highest ASCII value permitted for input.
  222.  
  223. The string the user enters is returned in ip$.
  224.  
  225. For example, to input a 3-digit number:
  226.  
  227. msg$="Enter Number:"
  228. mx% = 3
  229. ll% = 48  :' ASCII value of "0"
  230. ul% = 57  :' ASCII value of "9"
  231. CALL inpbox(msg$, ip$, mx%, ll%, ul%)
  232. number% = val(ip$)
  233. print "You Entered ";ip%
  234.  
  235. -----------------------------------------------------------------------------
  236. * SUB menupick (title$, mb$(), help$(), choice%)
  237.  
  238. Allows user to choose from a menu using either
  239. the mouse or the cursor keys.  This is the typical
  240. "vertical" menu displayed in the center of the screen,
  241. with a highlighted bar than can be moved with the
  242. mouse or crsr keys.  Screen is saved upon calling
  243. and automatically restored when done.
  244.  
  245. title$ = title to display on menu
  246. mb$() = text for menu choices
  247. help$() = one-line help message for each menu option
  248. choice% = choice returned by the user (0 if cancelled).
  249.  
  250. Set the cursor position (using LOCATE) to where you want
  251. the upper left corner of the menu before calling this
  252. routine.  help$() must be dimensioned to the same value
  253. as mb$(), but need not be defined.  For ONE helpline for
  254. all menu selections, set help$(1) to the text desired.
  255.  
  256. Example: title$="Select an Option"
  257.      redim mb$(2),help$(2)
  258.      mb$(1)="Option 1":mb$(2)="Option 2"
  259.      help$(1)="Select an option or press ESC to cancel"
  260.      CALL menupick(title$, mb$(), help$(), choice%)
  261.      print "You Picked ";choice%
  262.  
  263. -----------------------------------------------------------------------------
  264. * SUB messagebox (title$, msg$())
  265.  
  266. This routine prints a multi-line message in a box and exits
  267. without delay.  Use for messages you want to remain on the
  268. screen.  Title$ is printed at the top of the box, followed by
  269. a horizontal line, followed by the text in msg$().  Upon exit,
  270. the cursor is located at the position corresponding to the upper
  271. left corner of the box.  You can use this to calculate where to
  272. print further messages inside the box.
  273.  
  274. Example: LOCATE 10, 10
  275.      redim msg$(1:1)
  276.      title$="Loading..."
  277.      msg$(1)="Record #:"
  278.      call messagebox(title$, msg$())
  279.      LOCATE csrlin+3, pos(0)+11
  280.      print "5";  'Print Record #
  281.  
  282. -----------------------------------------------------------------------------
  283. * SUB mgetpos
  284.  
  285. Checks current position of mouse cursor and updates the
  286. corresponding global variables msy% and msx%.
  287.  
  288. Example: CALL mgetpos
  289.      PRINT msy%; msx%
  290.  
  291. -----------------------------------------------------------------------------
  292. * SUB mgetpress (button%, numpresses&, ycc%, xcc%)
  293.  
  294. Checks button indicated in button% (1 = left, 2 = right)
  295. and returns status of buttons in globals lb% and rb%, number
  296. of presses of specified button since last call (in numpresses&),
  297. and Y and X coordinates of mouse cursor the last time the specified
  298. button was pressed (in ycc% and xcc%).
  299.  
  300. Example: CALL mgetpress(button%, numpresses&, ycc%, xcc%)
  301.  
  302. -----------------------------------------------------------------------------
  303. * SUB mgetrelease (button%, numreleases&, ycc%, xcc%)
  304.  
  305. Checks button indicated in button% (1 = left, 2 = right)
  306. and returns status of buttons in globals lb% and rb%, number
  307. of releases of specified button since last call (in numreleases&),
  308. and Y and X coordinates of mouse cursor the last time the specified
  309. button was released (in ycc% and xcc%).
  310.  
  311. Example: CALL mgetrelease(1, numreleases&, ycc%, xcc%)
  312.  
  313. -----------------------------------------------------------------------------
  314. * SUB mousepick (ypos%(), xmin%(), xmax%(), pick%)
  315.  
  316. Checks arrays to see if mouse cursor is at positions specified
  317. in: ypos%(x) = line, xmin%(x) = minimum x pos. on line ypos%(x)
  318. and xmax%(x) = maximum x pos. on line ypos%(x).  If mouse cursor is
  319. at any of these locations (inclusive) AND left button is pressed,
  320. hilights desired area, waits til left button released, then returns
  321. with position number in pick%.
  322.  
  323. This routine requires quite a bit of setting up to use effectively,
  324. but essentially simulates a number of "buttons" on the screen that
  325. can be "pressed" with the mouse.  This routine does not utilize the
  326. keyboard at all, just the mouse, and you must draw the "buttons" on
  327. the screen first before calling the routine.  DIM the arrays to the
  328. number of "buttons" desired, Specify the Y position of each "button"
  329. in ypos%(), the minimum (lowest) X position of each "button" in
  330. xmin%(), and the maximum (highest) X position of each button in
  331. xmax%().
  332.  
  333. Example: DIM ypos%(1:5), xmin%(1:5), xmax%(1:5): '5 "buttons"
  334.      ... draw 5 "buttons" on the screen
  335.      ... (set ypos%(1) thru ypos%(5), same with xmin%()
  336.           and xmax%()
  337.      CALL mousepick(ypos%(), xmin%(), xmax%(), pick%)
  338.      'Check to see if any of the "buttons" were pressed,
  339.       if so, return the button number in pick%.
  340.  
  341. -----------------------------------------------------------------------------
  342. * SUB msetpos
  343.  
  344. Uses global variables msy% and msx% to set a new
  345. position for the mouse cursor.  Change msy% and/or
  346. msx% before calling this routine.
  347.  
  348. Example: msy% = 1: msx% = 1: CALL msetpos
  349.  
  350. -----------------------------------------------------------------------------
  351. * SUB mwaitpress
  352.  
  353. Waits for a Mouse Button to be Pressed.
  354.  
  355. Example: CALL mwaitpress
  356.  
  357. -----------------------------------------------------------------------------
  358. * SUB mybounds (mn%, mx%)
  359.  
  360. Sets minimum and maximum y-axis boundaries for mouse cursor
  361. movement.
  362.  
  363. Example: CALL mybounds(2, 24)
  364.  
  365. -----------------------------------------------------------------------------
  366. * FUNCTION pathstring$
  367.  
  368. Returns current disk/path in a string of the
  369. form C:\QB\EXE\ ... Trailing backslash included.
  370.  
  371. Example: PRINT pathstring$
  372.  
  373. -----------------------------------------------------------------------------
  374. * SUB picklist (lst$(), choice%)
  375.  
  376. *P*
  377.  
  378. Lets the user pick from a long list of options in a window, sizing
  379. and scrolling the window as necessary.  Set lst$() to the text for
  380. the list.  User's choice is returned in choice% (0 if cancelled).
  381.  
  382. Example: DIM lst$(100)
  383.      ... Read in text file to lst$(x)
  384.      CALL picklist(lst$(), choice%)
  385.      PRINT "You Picked ";choice%
  386.  
  387. -----------------------------------------------------------------------------
  388. * SUB printborder
  389.  
  390. Prints a border around the text screen
  391.  
  392. Example: CALL printborder
  393.  
  394. See demo program.
  395.  
  396. -----------------------------------------------------------------------------
  397. * SUB printtitle (title$, starty%, hilight%)
  398.  
  399. Prints a title on the screen, either highlighted
  400. or not highlighted.  See the demo program (title
  401. is printed one line below the menu bar at the top).
  402.  
  403. Example: CALL printtitle("Program.dat", 20, 1)
  404.  
  405. -----------------------------------------------------------------------------
  406. * SUB radiobox (title$, optn$(), choice%)
  407.  
  408. Displays a "radio button box" and lets user select one
  409. option from a list of options.  Set title$ to title of
  410. radio button box, optn$() to the options.  User's choice
  411. is returned in choice%.  Use instead of checkbox if only
  412. one option is possible out of a list of many.
  413. If cancelled (with ESC), choice% = 0.
  414.  
  415. Example: DIM optn$(3)
  416.      optn$(1) = "Option 1"....
  417.      CALL radiobox("Pick One",optn$(), choice%)
  418.      PRINT "You Chose ";choice%
  419.  
  420. -----------------------------------------------------------------------------
  421. * SUB screenedit (x1%, x2%, y1%, y2%, ky$)
  422.  
  423. *P*
  424.  
  425. An advanced routine that allows a user to edit a portion of the
  426. screen, using all the normal cursor keys and editing controls.
  427. This is one routine that's made to be edited and modified, so
  428. be sure to register and get the source code version of MENULIB.
  429.  
  430. x1%, x2% = Minimum and Maximum X Positions allowed (1-80).
  431. y1%, y2% = Minimum and Maximum Y Positions allowed (1-25).
  432. ky$ = keypress returned (if ESC or a scancode key is
  433.       pressed that the routine doesn't recognize).
  434.  
  435. Example: CALL screenedit(1, 80, 1, 25, ky$)
  436.  
  437. -----------------------------------------------------------------------------
  438. * SUB scrolldown (y1%, x1%, y2%, x2%, atrb%, ln%)
  439.  
  440. Scrolls a specified window of the screen down.
  441. y1%,x1% = Upper Left Corner
  442. y2%,x2% = Lower Right Corner
  443. atrb% = Attrib stored in blanked area
  444. ln% = Number of lines to scroll
  445. Note: x/y pos start from 0 instead of 1
  446.  
  447. This routine is a duplicate of mscrolldown in MENUSYS, with
  448. the parameters changed around a bit.  Use whichever you
  449. prefer.
  450.  
  451. Example: CALL scrolldown(1, 1, 25, 80, 7, 1)
  452.  
  453. -----------------------------------------------------------------------------
  454. * SUB scrollup (y1%, x1%, y2%, x2%, atrb%, ln%)
  455.  
  456. Scrolls a specified window of the screen up.
  457. y1%,x1% = Upper Left Corner
  458. y2%,x2% = Lower Right Corner
  459. atrb% = Attrib stored in blanked area
  460. ln% = Number of lines to scroll
  461. Note: x/y pos start from 0 instead of 1
  462.  
  463. This routine is a duplicate of mscrollup in MENUSYS, with
  464. the parameters changed around a bit.  Use whichever you
  465. prefer.
  466.  
  467. Example: CALL scrollup(1, 1, 25, 80, 7, 1)
  468.  
  469. -----------------------------------------------------------------------------
  470. * SUB selectback(ch%)
  471.  
  472. *P*
  473.  
  474. Allows a user to select a background color from a menu, and
  475. returns selection in cl% ... -1 if user cancelled.
  476.  
  477. Example: CALL selectback(ch%)
  478.  
  479. -----------------------------------------------------------------------------
  480. * SUB selectfore (cl%)
  481.  
  482. *P*
  483.  
  484. Allows a user to select a foreground color from a menu, and
  485. returns selection in cl% ... -1 if user cancelled.
  486.  
  487. Example: CALL selectfore(cl%)
  488.  
  489. -----------------------------------------------------------------------------
  490. * SUB setdisk (d%)
  491.  
  492. Sets disk in d% to be default (current drive):
  493. 0 = A, 1 = B, 2 = C, etc.
  494. Returns number of logical drives in system in d%.
  495.  
  496. Example: CALL setdisk(0) :' Set to A:
  497.  
  498. -----------------------------------------------------------------------------
  499. * SUB showtextfile (fi$, clr%)
  500.  
  501. *P*
  502.  
  503. An advanced routine that displays a textfile specified in fi$.
  504. Set clr% to the foreground color to display the text file in
  505. before calling this routine.  This is one routine that's made
  506. to be edited and modified, so be sure to register and get the
  507. source code version of MENULIB.
  508.  
  509. Example: CALL showtextfile("test.dat", 15)
  510.  
  511. -----------------------------------------------------------------------------
  512. * SUB sounds (num%)
  513.  
  514. Plays a sound on the PC's speaker.
  515. Set num% to:
  516.  
  517. 1 = popup
  518. 2 = popdown
  519. 3 = klaxon
  520. 4 = siren
  521. 5 = blip
  522. 6 = 2-tone
  523. 7 = 2-tone triple
  524. 8 = 3-tone
  525. 9 = buzz
  526. 10 = chirp
  527. 11-14 = beep1-4
  528. 15 = 60hz
  529.  
  530. Example: CALL sounds(1)
  531.  
  532. -----------------------------------------------------------------------------
  533. * FUNCTION startofline% (ln%)
  534.  
  535. Finds the position of the START OF TEXT on a specified screen line.
  536. For example, if line 20 of the screen had the line
  537.  
  538.  
  539.     This is a test
  540.  
  541.     ^
  542.     5
  543.  
  544. on it, PRINT startofline%(20) would return 5 (the position of
  545. the first character on the line).  If there is no text on the
  546. specified screen line, a value of 1 will be returned.
  547.  
  548. Example: a% = startofline%(2)
  549.  
  550. -----------------------------------------------------------------------------
  551. * SUB vscrollbar (starty%, startx%, length%)
  552.  
  553. Displays a vertical "scroll bar" on the screen starting at position
  554. starty%/startx%m, of length% characters (vertically).  See the demo
  555. program for an example of vscrollbar.  This routine displays the
  556. scrollbar only - does not control scrolling or anything else.  You
  557. will have to write the routines yourself to display a scroll indicator,
  558. or wait for a future version of menulib <grin>.
  559.  
  560. Example: CALL vscrollbar (1, 78, 15)
  561.  
  562. -----------------------------------------------------------------------------
  563. * SUB yesnobox (msg$, choice%)
  564.  
  565. Prints a one-line message on the screen in a box,
  566. and waits for user to select YES, NO or CANCEL.
  567. Returns 1 (YES), 0 (NO) or -1 (Cancel) in choice%.
  568. Shortest string should be >20.
  569.  
  570. Example: CALL yesnobox("Are you Sure?", choice%)
  571.  
  572. -----------------------------------------------------------------------------
  573.